package com.qn.visitor.intercept.handler;


import com.qn.visitor.intercept.IRuleIntercept;
import com.qn.visitor.model.bo.intercept.InterceptRule;
import com.qn.visitor.model.bo.intercept.InterceptSource;

import java.util.List;
/**
 * qingniu-cloud user source analysis
 *
 * @Author: TXG
 * @Date: 2024/6/11
 * @Version V0.0.2
 */
public abstract class BaseInterceptHandler implements IRuleIntercept {
    protected IRuleIntercept intercept;
    protected BaseInterceptHandler handler;

    public BaseInterceptHandler(IRuleIntercept intercept, BaseInterceptHandler handler) {
        this.intercept = intercept;
        this.handler = handler;
    }

    @Override
    public Integer execute(String atom, List<String> rules) {
        return intercept.execute(atom, rules);
    }

    protected Boolean isSuccess(Integer state) {
        if (state != null && state.equals(EXECUTE_SUCCESS)) {
            return true;
        }
        return false;
    }

    /**
     * 执行拦截
     * @param rule 规则
     * @param source 元数据
     * @return 拦截器Handler
     */
    public abstract BaseInterceptHandler intercept(InterceptRule rule, InterceptSource source);

    /**
     *获取拦截器名称
     * @return 拦截器名称
     */
    public abstract String getInterceptName();
}
